<template>
	<view class="passenger-flow">
		<view class="box_9">
			<con-venues :itemChooselist='itemChooselist' :venuelist='venuelist' @confirm="confirm1"></con-venues>
			<view style="position: fixed;z-index: 999;width: 100%;top: 120rpx;">
				<view class="box_11">
					<view class="image-wrapper_7">
						<u-search @search="search" @custom="search" placeholder="搜索" :showAction="false"
							v-model="searchKey">
						</u-search>
					</view>
					<view class="label_list" @click="plbatch" v-if="plshow">
						<image
							src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/0555f554c12d0d628b0e4e3e90147966755aa715.png"
							class="label_7"></image>
						<view class="label_77">
							批量
						</view>
					</view>
					<view class="label_list" @click="plbatch" v-if="!plshow">
						<image
							src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/0555f554c12d0d628b0e4e3e90147966755aa715.png"
							class="label_7"></image>
						<view class="label_77">
							设置
						</view>
					</view>
					<view class="label8_list">
						<image
							src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/a0caafa1d0f5c11490a41f203aab143debf439d6.png"
							class="label_8"></image>
						<view class="label_88">
							<!-- 筛选 -->
							<HM-filterDropdown :menuTop="88" :filterData="filterData" :defaultSelected="defaultSelected"
								:updateMenuName="true" @confirm="confirm" dataFormat="Object"></HM-filterDropdown>
						</view>
					</view>
				</view>
				<!-- <view class="all_whole">
					<view class="alls_potent">
						<view class="alls_shuju1">
							学员数据看板
						</view>
						<view class="alls_shuju2">
							<image class="alls_shuju2_img" src="../../static/logo.png" mode=""></image>
						</view>
					</view>
					<view class="all_whole_be">
						<view class="all_whole_or bg-color-all">
							<view class="wz-color-all1">
								全部
							</view>
							<view class="wz-color-all2">
								342
							</view>
						</view>
						<view class="all_whole_or bg-color-reading">
							<view class="wz-color-all1">
								在读
							</view>
							<view class="wz-color-reading2">
								342
							</view>
						</view>
						<view class="all_whole_or bg-color-graduated">
							<view class="wz-color-all1">
								结业
							</view>
							<view class="wz-color-graduated2">
								342
							</view>
						</view>
						<view class="all_whole_or bg-color-potential">
							<view class="wz-color-all1">
								潜在
							</view>
							<view class="wz-color-potential2">
								342
							</view>
						</view>
					</view>
					<view class="all_potent">
						<view class="all_shuju1">
							数据更新于:2024-01-15 10:30
						</view>
						<view class="all_shuju2">
							<image class="all_shuju2_img" src="../../static/logo.png" mode=""></image>
							<view class="">
								更新
							</view>
						</view>
					</view>
				</view> -->
			</view>
			<!-- 选择会员 -->
			<view class="" style="margin-top: 74rpx;">
				<scroll-view scroll-y class="listall" v-for="(item,index) in hylist" :key="index" v-if="plshow">
					<v-gap />
					<view class="d-flex flex-column listsee">
						<view class="d-flex flex-row justify-space-between">
							<view class="d-flex flex-row align-center">
								<view class="">
									<image style="width: 80rpx;height: 80rpx;border-radius: 50%;"
										:src="item.head_img" mode=""></image>
								</view>
								<view class="d-flex flex-column" style="margin-left: 20rpx;">
									<view class="" style="font-size: 26rpx;">
										{{item.name?item.name:''}} 
										<text style="margin-left: 20rpx;" v-if="item.sex == 1">男</text>
										<text style="margin-left: 20rpx;" v-if="item.sex == 2">女</text>
									</view>
									<view class="" style="color: #c2c2c2;font-size: 24rpx;margin-top: 10rpx;">
										{{item.mobile?item.mobile:''}}
									</view>
								</view>
							</view>
							<view class="d-flex flex-row align-center">
								<!-- <view class=""
									style="width: 80rpx;height: 50rpx;background: #ccffcc;color: #7cc57e;font-size: 24rpx;text-align: center;border-radius: 25rpx;margin-right: 20rpx;line-height: 50rpx;">
									{{item.sex}}
								</view> -->
								<view class="" @click="onedit(item,index)">
									<image style="width: 30rpx;height: 30rpx;margin-right: 20rpx;" src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/7886aba3ece8aae3b489b1944b48572a4f092c41.png" mode="">
									</image>
								</view>
								<view class="" @click="ondelete(item,index)">
									<image style="width: 30rpx;height: 30rpx;" src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/fe85ef51643a187a6090a929b34e93738e12e365.png" mode="">
									</image>
								</view>
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="" style="width: 250rpx;">
								年龄：{{item.age?item.age:''}}岁
							</view>
							<view class="">
								紧急联系人手机号：{{item.custodian_mobile}}
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="" style="width: 250rpx;">
								生日：{{item.birthday?item.birthday:''}}
							</view>
							<view class="">
								年级：{{item.grade_name_show?item.grade_name_show:''}}
							</view>
						</view>
						<view class="d-flex flex-row justify-space-between"
							style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class=""></view>
							<view class="" @click="handSelects(item)"
								style="width: 200rpx;height: 50rpx;background: linear-gradient(0deg, rgba(214, 53, 53, 0.9), rgba(255, 64, 64, 0.93), rgba(250, 142, 142, 0.93));color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 25rpx;line-height: 50rpx;">
								课包详情
							</view>
						</view>
					</view>
				</scroll-view>
				<scroll-view scroll-y class="listall" v-for="(item,index) in hylist" :key="index" v-if="!plshow"
					@click="handSelect(item)">
					<v-gap style="margin-top: 30rpx;" />
					<view class="d-flex flex-column listsee" :class="{'active1': weekSelect.includes(item.id)}">
						<view class="d-flex flex-row justify-space-between">
							<view class="d-flex flex-row align-center">
								<view class="">
									<image style="width: 80rpx;height: 80rpx;border-radius: 50%;"
										:src="item.head_img" mode=""></image>
								</view>
								<view class="d-flex flex-column" style="margin-left: 20rpx;">
									<view class="" style="font-size: 26rpx;">
										{{item.name}} 
										<text style="margin-left: 20rpx;" v-if="item.sex == 1">男</text>
										<text style="margin-left: 20rpx;" v-if="item.sex == 2">女</text>
									</view>
									<view class="" style="color: #c2c2c2;font-size: 24rpx;">
										{{item.mobile}}
									</view>
								</view>
							</view>
							<!-- <view class="d-flex flex-row align-center">
								<view class=""
									style="width: 80rpx;height: 50rpx;background: #ccffcc;color: #7cc57e;font-size: 24rpx;text-align: center;border-radius: 25rpx;margin-right: 20rpx;line-height: 50rpx;">
									在读
								</view>
								<view class="">
									<image style="width: 30rpx;height: 30rpx;" src="../../static/logo.png" mode="">
									</image>
								</view>
							</view> -->
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="" style="width: 250rpx;">
								年龄：{{item.age}}岁
							</view>
							<view class="">
								紧急联系人手机号：{{item.custodian_mobile}}
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="" style="width: 250rpx;">
								生日：{{item.birthday}}
							</view>
							<view class="">
								年级：{{item.grade_name_show}}
							</view>
						</view>
						<!-- <view class="d-flex flex-row justify-space-between"
							style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="">
								生日：{{item.birthday}}
							</view>
							<view class="" @click="handSelects(item)"
								style="width: 200rpx;height: 50rpx;background: linear-gradient(0deg, rgba(214, 53, 53, 0.9), rgba(255, 64, 64, 0.93), rgba(250, 142, 142, 0.93));color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 25rpx;line-height: 50rpx;">
								课包详情
							</view>
						</view> -->
					</view>
				</scroll-view>
				<v-gap height="140rpx" color="#EDF5F5" />
			</view>
			<view class="d-flex flex-row justify-space-between justify-center align-center"
				style="position: fixed;bottom: 0;height: 120rpx;background-color: #fff;width: 100%;padding: 0 8%;z-index: 99;">
				<view class="" @click="plbatch" v-if="plshow"
					style="width: 45%;height: 80rpx;background: #ffffff;color: #ff4040;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;border:#ff4040 1rpx solid">
					批量操作
				</view>
				<view class="" v-if="!plshow" @click="selectAllWeeks"
					style="width: 45%;height: 80rpx;background: #ffffff;color: #ff4040;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;border:#ec6ff404052b 1rpx solid">
					全选
				</view>
				<view class="" @click="addstudent"
					style="width: 45%;height: 80rpx;background: linear-gradient(0deg, rgba(214, 53, 53, 0.9), rgba(255, 64, 64, 0.93), rgba(250, 142, 142, 0.93));color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;">
					添加学员
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	const lastdata = [{
		"name": '筛选',
		"type": 'filter',
		"submenu": [{
				"name": "性别",
				"submenu": [{
						"name": "男",
						"value": "1"
					},
					{
						"name": "女",
						"value": "2"
					}
				]
			},
			{
				"name": "机构",
				"submenu": [{
						"name": "总部",
						"value": "1"
					},
					{
						"name": "分布A",
						"value": "2"
					},
					{
						"name": "分布B",
						"value": "3"
					}
				]
			},
			{
				"name": "转态",
				"submenu": [{
						"name": "在读",
						"value": "4"
					},
					{
						"name": "休学",
						"value": "5"
					},
					{
						"name": "结业",
						"value": "6"
					}
				]
			},
			{
				"name": "年龄",
				"submenu": [{
						"name": "6-8岁",
						"value": "4"
					},
					{
						"name": "9-12岁",
						"value": "5"
					},
					{
						"name": "13-15岁",
						"value": "6"
					}
				]
			}
		]
	}];
	const personal = require("@/api/personal/index.js");
	const venues = require("@/api/venues/venues.js");
	export default {
		data() {
			return {
				filterData: [],
				itemChooselist: {},
				venuelist: [],
				plshow: true,
				weekSelect: [], //选中的
				hylist: [{
						id: '1',
						name: '篮球训练'
					},
					{
						id: '2',
						name: '游泳课程'
					},
					{
						id: '3',
						name: '瑜伽课程'
					},
					{
						id: '4',
						name: '健生教练'
					},
					{
						id: '5',
						name: '羽毛球培训'
					},
				],
				isAllSelect: false, //是否全选
				listQuery: { //分页
					pageNo: 1,
					pageSize: 6,
				},
				totalPage: '', //几页
				studentlist:[],
				searchKey:"",
				venue_id:''
			}
		},
		onLoad(options) {
			var data = uni.getStorageSync("wqzdy");
			var items = JSON.parse(data)
			this.venuelist = items
			// this.itemChooselist = this.venuelist[0]
			// 处理itemChooselist的逻辑
			if (this.venuelist.length > 0) {
				this.itemChooselist = this.venuelist[0]
				this.venue_id = this.venuelist[0].id
			} else {
				this.itemChooselist = {}; // 或者设置为其他默认值
			}
			setTimeout(() => {
				this.filterData = lastdata;
			}, 100);
		},
		onShow() {
			this.listQuery.pageNo = 1
			this.studentindex()
		},
		methods: {
			async studentindex() {
				let that = this;
				if (this.listQuery.pageNo === 1) that.hylist = [];
				let params = {
					keyword:this.searchKey,
					pageSize:this.listQuery.pageSize,
					page:this.listQuery.pageNo,
					venue_id:this.venue_id,
				}
				let res = await venues.studentindex(params)
				if (res.code === 1) {
					// this.hylist = res.data.list.data
					that.hylist = that.hylist.concat(res.data.list.data); //将数据拼接在一起
					that.totalPage = res.data.list.last_page
				}
			},
			// 下拉刷新
			onReachBottom() {
				if (this.totalPage <= this.listQuery.pageNo) {
					uni.showToast({
						title: '没有更多了',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				this.listQuery.pageNo += 1;
				this.studentindex()
			},
			search(e){
				this.listQuery.pageNo = 1
				this.searchKey = e
				this.studentindex()
			},
			onedit(item,index){
				uni.navigateTo({
					url: `../addstudent/index?selectionArr=${encodeURIComponent(JSON.stringify(item))}` + "&status=" + 1 + "&venue_id=" + this.venue_id
				})
			},
			ondelete(item,index){
				let that = this
				uni.showModal({
					title: '提示',
					// 提示文字
					content: '是否删除！',
					// 取消按钮的文字自定义
					cancelText: "取消",
					// 确认按钮的文字自定义
					confirmText: "确定",
					//删除字体的颜色 
					confirmColor: '#000000',
					//取消字体的颜色
					cancelColor: '#999',
					success: function(res) {
						if (res.confirm) {
							let params = {
								id: item.id
							};
							venues.studentdel(params).then(res => {
								if (res.code == 1) {
									uni.$u.toast(res.info);
									setTimeout(() => {
										that.studentindex()
									}, 1000)
								}
							})
						} else {
						}
					}
				})
			},
			// 新增的全选方法
			selectAllWeeks() {
			  if (this.weekSelect.length === this.hylist.length) {
			    // 如果已全选，则清空选中数组
			    this.weekSelect = [];
			  } else {
			    // 如果未全选，则选中所有项目
			    this.weekSelect = this.hylist.map(item => item.id);
			  }
			},
			handSelect(item) {
				let data = item.id;
				// 使用indexOf检查是否已选中，避免重复或遗漏
				const index = this.weekSelect.indexOf(data);
				if (index > -1) {
					// 如果已选中，则移除
					this.weekSelect.splice(index, 1);
				} else {
					// 如果未选中，则添加
					this.weekSelect.push(data);
				}
			},
			handSelects(item) {
				uni.navigateTo({
					url: '../studentdetail/index?student_id=' + item.id
				})
			},
			plbatch() {
				this.plshow = !this.plshow
			},
			confirm(e) {
				uni.navigateTo({
					url: './shaixuan'
				})
				// this.indexArr = e.index;
				// this.valueArr = e.value;

			},
			confirm1(data) {
				this.venue_id = data
			    console.log(data, 'data');
			    // 直接根据接收到的 id 在 venuelist 中查找对应的场馆对象
			    const selectedItem = this.venuelist.find(item => item.id === data);
			    if (selectedItem) {
			        // 将找到的场馆对象赋值给 itemChooselist
			        this.itemChooselist = selectedItem;
			    } else {
			        console.log(`未找到 id 为 ${data} 的场馆对象`);
			    }
			    this.studentindex()
			},
			addstudent() {
				uni.navigateTo({
					url: '../addstudent/index?venue_id=' + this.venue_id + "&status=" + 2 
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	// @import '../../static/css/member/member_index.scss';
	.passenger-flow {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		background-color: #EDF5F5;
		padding: 0rpx 0 50rpx 0;
		position: relative;

		.box_9 {
			width: 750rpx;
			height: 100%;
			// margin-bottom: 1rpx;
			display: flex;
			flex-direction: column;

			.tag-list {
				display: flex;
				margin-top: 30rpx;
				padding: 0 20rpx;

				/deep/ view {
					margin-left: 4rpx;
				}
			}

			.box_11 {
				width: 100%;
				height: 130rpx;
				display: flex;
				flex-direction: row;
				background: #ffffff;
				padding: 0 20rpx;

				// .image-wrapper_7 {
				// 	width: 541rpx;
				// 	height: 60rpx;
				// 	flex-direction: row;
				// 	display: flex;
				// 	margin-top: 15rpx;
				// }
				.image-wrapper_7 {
					position: absolute;
					left: 30rpx;
					top: 30rpx;
					width: 541rpx;
					height: 62rpx;
					flex-direction: row;
					display: flex;
				}

				.label_list {
					display: flex;
					flex-direction: column;
					position: absolute;
					justify-content: center;
					/* 相对父元素水平居中 */
					align-items: center;
					/*  子元素相对父元素垂直居中 */
					right: 90rpx;
					width: 80rpx;
					top: 27rpx;

					.label_7 {
						width: 36rpx;
						height: 36rpx;
					}

					.label_77 {
						width: 60rpx;
						height: 36rpx;
						color: #333333;
						font-size: 26rpx;
						text-align: center;
					}
				}

				.label8_list {
					display: flex;
					flex-direction: column;
					position: absolute;
					justify-content: center;
					/* 相对父元素水平居中 */
					align-items: center;
					/*  子元素相对父元素垂直居中 */
					right: 20rpx;
					width: 80rpx;
					top: 27rpx;

					.label_8 {
						width: 36rpx;
						height: 36rpx;
					}

					.label_88 {
						width: 60rpx;
						height: 36rpx;
						color: #333333;
						font-size: 26rpx;
						text-align: center;
					}
				}
			}

			.all_whole {
				width: 100%;
				display: flex;
				flex-direction: column;
				background: #ffffff;

				.all_whole_be {
					display: flex;
					flex-direction: row;
					justify-content: space-around;

					.all_whole_or {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						width: 20%;
						height: 150rpx;
						border-radius: 20rpx;
					}

					/* 使用类名来设置背景色 */
					.bg-color-all {
						background: linear-gradient(0deg, rgb(173, 201, 246) 0%, rgb(231, 239, 255) 100%);
					}

					.bg-color-reading {
						background: linear-gradient(0deg, #ccffcc 0%, #edffea 100%);
					}

					.bg-color-graduated {
						background: linear-gradient(0deg, #fbdafd 0%, #fdeffd 100%);
					}

					.bg-color-potential {
						background: linear-gradient(0deg, #f9ffcf 0%, #fdffe9 100%);
					}

					.wz-color-all1 {
						font-size: 24rpx;
					}

					.wz-color-all2 {
						color: #3479da;
						font-weight: 600;
						font-size: 26;
					}

					.wz-color-reading2 {
						color: #67ca55;
						font-weight: 600;
						font-size: 26;
					}

					.wz-color-graduated2 {
						color: #a672c6;
						font-weight: 600;
						font-size: 26;
					}

					.wz-color-potential2 {
						color: #b39b64;
						font-weight: 600;
						font-size: 26;
					}
				}

				.all_potent {
					display: flex;
					flex-direction: row;
					justify-content: space-around;
					color: #c2c2c2;
					font-size: 22rpx;
					height: 80rpx;
					width: 100%;
					justify-content: space-between;
					align-items: center;
					padding: 0 20rpx;

					.all_shuju1 {}

					.all_shuju2 {
						display: flex;
						flex-direction: row;
						justify-content: center;
						align-items: center;

						.all_shuju2_img {
							width: 20rpx;
							height: 20rpx;
							margin-right: 10rpx;
						}
					}
				}

				.alls_potent {
					display: flex;
					flex-direction: row;
					justify-content: space-around;
					height: 80rpx;
					width: 100%;
					justify-content: space-between;
					align-items: center;
					padding: 0 20rpx;

					.alls_shuju1 {
						font-size: 28rpx;
					}

					.alls_shuju2 {
						display: flex;
						flex-direction: row;
						justify-content: center;
						align-items: center;

						.alls_shuju2_img {
							width: 20rpx;
							height: 20rpx;
						}
					}
				}
			}

			.listall {
				.listsee {
					background-color: #fff;
					padding: 30rpx;
					border-radius: 10rpx;
					width: 94%;
					margin-left: 3%;
					border: 2rpx #fff solid;
				}

				.active1 {
					border: 2rpx #0000ff solid;
				}
			}

		}
	}
</style>